package com.test.deencredit.bean_deencredit.userinfo_deencredit;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.test.deencredit.adapter_deencredit.HomeCarouselAdapter_deencredit;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.LinkedHashMap;


public class LnLimitInfo_deencredit {

    private static class Inner_deencredit {
        private static LnLimitInfo_deencredit instance_deencredit = new LnLimitInfo_deencredit();
    }

    private LnLimitInfo_deencredit(){}

    public static LnLimitInfo_deencredit getInstance_deencredit(){
        return Inner_deencredit.instance_deencredit;
    }

    private String newUserFlag;
    private ArrayList<LinkedHashMap<String,String>> limit;

    public static void parse_deencredit(JSONObject objJson){
        Inner_deencredit.instance_deencredit = new Gson().fromJson(objJson.toString(), LnLimitInfo_deencredit.class);
    }

    public boolean isNewUSer_deencredit() {
        if (TextUtils.isEmpty(newUserFlag)) return true;
        return !newUserFlag.equalsIgnoreCase("NO");
    }

    public String getLimitAmount_deencredit(){
        if (limit == null||limit.size()==0) return "";
        String result = limit.get(0).get("amount");
        if (TextUtils.isEmpty(result)) return "";
        return result;
    }

    public String getCurrency_deencredit() {
        if (limit == null||limit.size()==0) return "";
        String result = limit.get(0).get("currency");
        if (TextUtils.isEmpty(result)) return "";
        return result;
    }

    /**
     *  increasedAmount1,increasedAmount2,increasedAmount3...
     *  lock1,lock2,lock3...    (默认为true)
     */
    public ArrayList<HomeCarouselAdapter_deencredit.HomeCarouseInfo_deencredit> getHomeCarouseInfos_deencredit(){

        ArrayList<HomeCarouselAdapter_deencredit.HomeCarouseInfo_deencredit> result = new ArrayList<>();

        if (limit == null||limit.size()==0) return result;


        LinkedHashMap<String,String> linkedHashMap = limit.get(0);

        int count=0;
        while (++count<10){

            String increasedAmount = linkedHashMap.get("increasedAmount"+count);
            if (TextUtils.isEmpty(increasedAmount)) return result;

            String lockStr = linkedHashMap.get("lock"+count);
            result.add(new HomeCarouselAdapter_deencredit.HomeCarouseInfo_deencredit(increasedAmount,!(!TextUtils.isEmpty(lockStr) && lockStr.equalsIgnoreCase("NO"))));

        }

        return result;
    }

}
